<?php
	//
	//This php will handle the 
	// UserFetch.java 
	// - fetchUserById function
	//
	
	//Connect to database
	include '../../dbc.php';
	
	$user_in = $_POST['user'];
	
	//Select non-blocked restaurant
	//Get the list of user we are following
	$query02 = "SELECT * FROM user_follow WHERE user='$user_in'";
    $query02_result = mysql_query($query02);
	if(mysql_num_rows($query02_result) > 0){
		$i = 0;
		
		$query01 = "SELECT * FROM meal_comment WHERE is_blocked='0' AND (";
		$isFirst = true;
		while($query02_result_row = mysql_fetch_array($query02_result)){
			if($isFirst){
				$isFirst = false;	
			}else{
				$query01 = 	$query01." OR ";
			}
			$query01 = 	$query01." user='";
			$query01 = 	$query01.$query02_result_row['user_follow'];
			$query01 = 	$query01."'";
		}
		$query01 = $query01.") ORDER BY create_date DESC";
		
		$query01_result = mysql_query($query01);
		if(mysql_num_rows($query01_result) > 0){
			while($query01_result_row = mysql_fetch_array($query01_result)){
				$id[$i] = $query01_result_row['id'];
				$user[$i] = $query01_result_row['user'];
				$meal[$i] = $query01_result_row['meal'];
				$rating[$i] = $query01_result_row['rating'];
				$comment[$i] = $query01_result_row['comment'];
				$create_date[$i] = $query01_result_row['create_date'];
				$i++;	
			}
			
			
			$response["STATUS"] = "1";
			$response["NUMBER"] = $i;
			$response["ID"] = $id;
			$response["USER"] = $user;
			$response["MEAL"] = $meal;
			$response["COMMENT"] = $comment;
			$response["CREATE_DATE"] = $create_date;
			
			echo json_encode($response);
		}
	}else{
		//Unable to get user
		$response["STATUS"] = "0";
		$response["NUMBER"] = "0";
		echo json_encode($response);
	}
	

?>